package com.yanqu.road.server.cmd.guess;

import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.CommonGuessProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.guess.CrossCommonGuessMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C2_COMMON_GUESS_SAVE_DATA, desc = "通用竞猜-保存竞猜数据")
public class CrossCommonGuessSaveDataCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CommonGuessProto.CommonGuessSaveDataReqCrossMsg reqMsg = CommonGuessProto.CommonGuessSaveDataReqCrossMsg.parseFrom(packet.getBytes());
        try {
            CrossCommonGuessMgr.saveData(packet.getPlayerId(), 0, reqMsg);
            CommonGuessProto.CommonGuessSaveDataFromCrossReqMsg.Builder respMsg = CommonGuessProto.CommonGuessSaveDataFromCrossReqMsg.newBuilder();
            respMsg.setActivityId(reqMsg.getActivityId());
            respMsg.setGroupId(0);
            respMsg.setRound(reqMsg.getRound());
            respMsg.setSiteId(reqMsg.getSiteId());
            respMsg.addAllObjIds(reqMsg.getObjIdsList());
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_COMMON_GUESS_SAVE_DATA_FROM_CROSS, respMsg));
        } catch (BusinessException e) {
            CommonGuessProto.CommonGuessSaveDataRespMsg.Builder respMsg = CommonGuessProto.CommonGuessSaveDataRespMsg.newBuilder();
            respMsg.setRet(e.getCode());
            MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_COMMON_GUESS_SAVE_DATA, respMsg));
        }
    }

    @Override
    public void sendData() {

    }
}
